package com.example.d6_homework.homework07;

import com.example.d6_homework.homework07.service.AtmService;
import com.example.d6_homework.homework07.service.impl.AtmServiceImpl;

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            try {
                System.out.println("请输入取钱金额: ");
                double drawMoney = sc.nextDouble();

                // 通过多态的方式创建AtmService对象
                AtmService atmService = new AtmServiceImpl();
                
                // 调用drawMoney方法进行取钱
                double money = atmService.drawMoney(drawMoney);

                // 输出剩余金额
                System.out.println("恭喜你,取钱成功! 本次取钱金额为：" + drawMoney + ", 剩余金额：" + money);
                break;
            } catch (Exception e) {
                System.out.println(e.getMessage() + "请重新输入金额");
            }
        }
    }
}
